/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.comandos.admin;

import br.ufc.quixada.adrs.interfaces.Comando;
import br.ufc.quixada.adrs.model.Adrs;
import br.ufc.quixada.adrs.util.Msg;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Welligton
 */
public class CmdBuscarAdrsPorNomeForaPrazo implements Comando {

    public String executa(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = request.getSession();
        List<Adrs> listaAdrsForaPrazo = (List<Adrs>) session.getAttribute("adrsForaPrazo");
        String nome = request.getParameter("nome_busca");

        if (nome == null || nome.trim().equals("")) {
            session.setAttribute("listaAdrsPrazo", listaAdrsForaPrazo);
        } else {
            List<Adrs> listaFinalAdrs = new ArrayList<Adrs>();
            for (Adrs adrs : listaAdrsForaPrazo) {
                if (adrs.getUsuario().getNome().contains(nome.toUpperCase())) {
                    listaFinalAdrs.add(adrs);
                }
            }
            if (listaFinalAdrs == null || listaFinalAdrs.isEmpty()) {
                session.setAttribute("erro", Msg.NOT_FOUND_ERROR_ADRSS);
            }

            session.setAttribute("listaAdrsPrazo", listaFinalAdrs);
        }
        return "/admin/admin_gerenciar_add_adrs_fora_prazo.jsp";
    }
}
